package com.google.code.tretris;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.google.code.tretris.debug.TextClientActivity;
import com.google.code.tretris.server.GamePlayService;

public class StartActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Button serverButton = (Button) findViewById(R.id.server_button);
		serverButton.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClassName("com.google.code.tretris",
						"com.google.code.tretris.InvitePlayersActivity");
				startActivity(intent);
			}
		});

		findViewById(R.id.graphical_client).setOnClickListener(
				new OnClickListener() {
					public void onClick(View v) {
						startActivity(new Intent(StartActivity.this,
								Tretris.class));
					}
				});

		Intent serviceIntent = new Intent(this, GamePlayService.class);
		startService(serviceIntent);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater menuInflater = getMenuInflater();
		menuInflater.inflate(R.menu.mainmenu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case R.id.settingsmenuitem: {
				SettingsDialog settingsDialog = new SettingsDialog(this) ;
				settingsDialog.show();
				break;
			}
			case R.id.serverconsolemenuitem: {
				Intent intent = new Intent(this, ServerConsoleActivity.class) ;
				startActivity(intent) ;
				break;
			}
			case R.id.textclientmenuitem: {
				startActivity(new Intent(StartActivity.this,
						TextClientActivity.class));
				break ;
			}
		}
		return super.onOptionsItemSelected(item);
	}

}
